var tablename = "student";
var app = this;
var $ = require("../../include/$");
module.exports = {
	get: function(req, res) {
		var data = req.query;
		id = data.tid == "undefined" ? data.sid : data.tid;
		data.tid == "undefined" ? tablename = "student" : tablename = "teacher";
		req.models[tablename].get(id, function(err, result) {
			if (err) {
				res.send(500, err);
			} else {
				res.send(result);
			};
		})
		console.log(id)
	},
	put: function(req, res) {
		var data = req.body;
		console.log(data);
		data.tid ? (id = data.tid) : (id = data.sid);
		data.tid ? (tablename = 'teacher') : tablename = 'student';
		console.log("为表“", tablename, "”进行修改：", req.body, req.query);
		req.models[tablename].get(id, function(err, result) {
			if (err) {
				console.log(err)
				res.send(500, err);
			} else {
				for (var key in data) {
					result[key] = data[key];
				};
				result.save(function(err) {
					if (err) {
						console.log("zheli:" + err)

						res.send(500, err);
					} else {
						res.send("ok");
						res.end();
					}
				});
			}
		});
	}
}